from typing import Dict, List, Optional
import logging
from .config import PaperAIConfig
from .modules.project import ProjectCore
from .modules.state import StateCore
from .db import SessionLocal


class PaperAICore:
    def __init__(self, config: PaperAIConfig):
        self.config = config

    def __get_session_instance(self):
        session = SessionLocal()
        try:
            yield session
        finally:
            session.close()

    def get_session(self):
        return next(self.__get_session_instance())

    @property
    def project(self) -> ProjectCore:
        return ProjectCore(self.get_session)

    def state(self, project_token: str) -> StateCore:
        return StateCore(self.get_session, project_token)

    def start(self):
        logger = logging.getLogger('core')
        logger.info('Loading core...')

